package com.example.trb.controller.performance;

import com.example.trb.dto.ObjectDTO;
import com.example.trb.entity.PerformanceResult;
import com.example.trb.entity.group.Insert;
import com.example.trb.entity.group.Update;
import com.example.trb.service.performance.PerformanceResultService;
import com.example.trb.util.result.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
public class PerformanceResultController {
    @Autowired
    PerformanceResultService prService;
    @Value("${session_user}")
    String userKey;

    @PutMapping("/performanceresult")
    public CommonResult putPerformanceResult(@RequestBody @Validated(Update.class) PerformanceResult data) {
        prService.update(data);
        return CommonResult.success(null);
    }

    @DeleteMapping("/performanceresult")
    public CommonResult deletePerformanceResult(@RequestBody PerformanceResult data) {
        prService.removeById(data.getId());
        return CommonResult.success(null);
    }


    @PostMapping("/performanceresult/status")
    public CommonResult status(@RequestParam("id") Integer id,@RequestParam("status") String status)  {
        prService.updateStatusById(id,status);
        return CommonResult.success(null);
    }

    @GetMapping("/performanceresult")
    public CommonResult getPerformanceResult(@RequestParam("id") Integer id) {
        ObjectDTO dto = prService.getById(id);
        return CommonResult.success(dto.getData());
    }

    @PostMapping("/performanceresult")
    public CommonResult addPerformanceResult(@RequestBody @Validated(Insert.class) PerformanceResult data) {
        ObjectDTO dto = prService.save(data);
        return CommonResult.success(dto.getData());
    }
}
